const express = require('express');
const router = express.Router();
const fs = require('fs');
// const usersRouter = require('C:\\www\\2302\\day33\\简单登录案例\\routers\\users');

// router.use('/users',usersRouter);



// const a = '/users'
// const 变量 = require('C:/www/2302/day33/简单登录案例/routers'+a);
// router.use(a,变量);

// const b = '/goods'
// const 变量 = require('C:/www/2302/day33/简单登录案例/routers'+b);
// router.use(b,变量);



// ['users','goods','cart']
// 遍历 routers 文件夹  拿到 ['users','goods','cart']
// 遍历数组  挨个取出 
//const 变量 = require('C:/www/2302/day33/简单登录案例/routers'+取出来的元素);
//router.use(取出来的元素,变量);
fs.readdir('C:\\www\\2302\\day33\\简单登录案例\\routers',(err,data)=>{
    if(err){
        return console.log(err);
    }
    // console.log(data);[ 'index.js', 'users.js' ]
    data = data.filter(item=>item !== 'index.js').map(item=>item.slice(0,-3))
    // console.log(data);


    data.forEach(item=>router.use('/'+item,require('C:/www/2302/day33/简单登录案例/routers/'+item)));
    console.log(data);
});

module.exports = router